﻿using NLog;

namespace Scheduler.Common.Helper
{
    /// <summary>
    /// nLog使用帮助类
    /// </summary>
    public class LoggerHelper
    {
        private readonly NLog.Logger logger = LogManager.GetCurrentClassLogger();//实例化nLog，即为获取配置文件相关信息(获取以当前正在初始化的类命名的记录器)
        private static LoggerHelper? _logger =null;
        private static readonly object _lock = new object();

        private LoggerHelper()
        {

        }
        private static readonly Lazy<LoggerHelper> loggerHelperLazy =new Lazy<LoggerHelper>(()=>new LoggerHelper());
        public static LoggerHelper Log
        {
            get
            {
                return loggerHelperLazy.Value;
            }
        }
        public static LoggerHelper Logger1
        {
            get => _logger ?? (new LoggerHelper());
            set => _logger = value;
        }
        public static LoggerHelper Logger
        {
            get
            {
                if (_logger == null)
                {
                    lock (_lock)
                    {
                        if (_logger == null)
                        {
                            _logger = new LoggerHelper();
                        }
                    }
                }
                return _logger;
            }
        }
        #region Debug，调试
        public void Debug(string msg)
        {
            logger.Debug(msg);
        }

        public void Debug(string msg, Exception err)
        {
            logger.Debug(err, msg);
        }
        #endregion

        #region Info，信息
        public void Info(string msg)
        {
            logger.Info(msg);
        }

        public void Info(string msg, Exception err)
        {
            logger.Info(err, msg);
        }
        #endregion

        #region Warn，警告
        public void Warn(string msg)
        {
            logger.Warn(msg);
        }

        public void Warn(string msg, Exception err)
        {
            logger.Warn(err, msg);
        }
        #endregion

        #region Trace，追踪
        public void Trace(string msg)
        {
            logger.Trace(msg);
        }

        public void Trace(string msg, Exception err)
        {
            logger.Trace(err, msg);
        }
        #endregion

        #region Error，错误
        public void Error(string msg)
        {
            logger.Error(msg);
        }
        public void Error(string msg, Exception err)
        {
            logger.Error(err, msg);
        }
        #endregion

        #region Fatal,致命错误
        public void Fatal(string msg)
        {
            logger.Fatal(msg);
        }

        public void Fatal(string msg, Exception err)
        {
            logger.Fatal(err, msg);
        }
        #endregion
    }
}
